package cn.hchaojie.ssm.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

/**
 * 拦截controller里面的方法，(handler)
 * @author hchaojie
 *
 */
public class InterceptorB implements HandlerInterceptor {
	/**
	 * 在controller方法执行之前运行，  （可以做登陆判断、权限检查）
	 * 
	 * 返回true的话，- 继续执行
	 * 返回false，	- 中断执行
	 */
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		System.out.println("preHandleB");
		
		return true;
	}

	/**
	 * contrller方法执行之后运行，但是在视图渲染之前
	 */
	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {
		System.out.println("postHandleB");
	}

	/**
	 * ontrller方法执行之后运行, 视图渲染完毕
	 */
	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
			throws Exception {
		System.out.println("afterCompletionB");
	}
	
}
